import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// 1引入element-plus组件库
import ElementPlus, {ElMessage} from 'element-plus'
import 'element-plus/dist/index.css'
// main.ts

// 如果您正在使用CDN引入，请删除下面一行。
// 3引入element-plus图标库
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)
// 4遍历引入进来的图标库ElementPlusIconsVue,并将每轮循环遍历到的图标全局注册到vue实例app中
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
// 2.use(ElementPlus)给vue实例配置element-plus组件库
app.use(ElementPlus, {
    locale: zhCn,
}).use(store).use(router).mount('#app')
window.getUser=()=>{
    return localStorage.user ? JSON.parse(localStorage.user) : null;
}
router.beforeEach((to,from,next)=>{
    let user=localStorage.user;
    if (to.path!=='/login' && !user){
        next({path:'/login'},ElMessage.error('请先登录'));
    }
    else
        next()
})
